package com.simon.train.business.controller.admin;


import com.simon.train.business.dto.TrainCarriageQueryDto;
import com.simon.train.business.dto.TrainCarriageSaveDto;
import com.simon.train.business.service.TrainCarriageService;
import com.simon.train.business.vo.TrainCarriageQueryVO;
import com.simon.train.common.Result.Result;
import com.simon.train.common.vo.PageVO;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/admin/trainCarriage")
public class TrainCarriageAdminController {

    @Resource
    private TrainCarriageService trainCarriageService;

    @PostMapping("/save")
    public Result<Object> SaveTrainCarriage(@Valid @RequestBody TrainCarriageSaveDto trainCarriageSaveDto){
        trainCarriageService.SaveTrainCarriage(trainCarriageSaveDto);
        return new Result<>();
    }

    @GetMapping("/queryList")
    public Result<PageVO<TrainCarriageQueryVO>> TrainCarriageQueryList(@Valid TrainCarriageQueryDto trainCarriageQueryDto){
         /**
         * businessId通过线程变量获取 从而不需要由前端传入 保证了效率和安全性
         */
        PageVO<TrainCarriageQueryVO> lists = trainCarriageService.QueryTrainCarriageList(trainCarriageQueryDto);
        return new Result<>(lists);
    }

    @DeleteMapping("/delete/{id}")
    public Result<Object> DeleteTrainCarriage(@PathVariable("id") Long id){
        trainCarriageService.deleteTrainCarriage(id);
        return new Result<>();
    }

}
